/* @(#)GSDataOperExpAction.java    V0.1
 *
 * Project: GSdevelop
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   vincent         2006-2-21
 *
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 * 
 */
package com.hitrust.gs.action;

import java.text.SimpleDateFormat;

import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.lib.GSLogWriter;
import com.hitrust.gs.lib.GSSystemConfigurator;
import com.hitrust.gs.lib.db.backup.DataOper;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.util.date.DateUtil;

/**
 * 
 */
public class GSDataOperExpAction extends GSBaseAction{

    public String execute(GSBaseForm aForm) throws Exception {
    
        SimpleDateFormat dftime = new SimpleDateFormat("yyyyMMdd");
        String buftime = dftime.format(new java.util.Date(System.currentTimeMillis()));
    
        StringBuffer tExpTemp = new StringBuffer();
//      tExpTemp = "exp system/sa@BUS file=d:/xxxx.dmp tables=(scott.EMP,scott.BONUS)";
        tExpTemp.append("exp ");
        tExpTemp.append(GSSystemConfigurator.getParam("gs.connectdatabase"));
        tExpTemp.append(" file="+GSSystemConfigurator.getParam("gs.backuppath")+buftime+".dmp");
        String tTemp=GSSystemConfigurator.getParam("gs.backuptable");
        tExpTemp.append(" buffer=8192000");
        tExpTemp.append(" compress=n");
        tExpTemp.append(" grants=y");
        
        if("all".equals(tTemp.toLowerCase()))
            //tExpTemp.append(" full=y");
            tExpTemp.append(" ");
        else
            tExpTemp.append(" tables=("+tTemp+")");
        int tResult=-1;
        GSLogWriter.debug("tExpTemp="+tExpTemp.toString());
        try {
            //系统时间
            
            //0 成功 1 备份失败
            tResult=new DataOper().dataFunction(tExpTemp.toString());
            GSLogWriter.info(DateUtil.getCurrentTime("DT", "AD")+"==backup data tResult="+tResult);
        } catch (Exception ex) {
            GSLogWriter.error(this,ex.getMessage());
        }
        if(tResult==0){
            aForm.getRequest().setAttribute("message","数据成功备份");
            aForm.getRequest().setAttribute("action","A500201.do");
            return GSBaseConstants.FORWARD_SUCCESS;
        }else{
            aForm.getRequest().setAttribute("message","数据备份出现异常详见日志信息");
            aForm.getRequest().setAttribute("action","A500201.do");
            return GSBaseConstants.FORWARD_SUCCESS;
        }
    }
}
